The MAGT1 transporter is critically involved in the selective regulation of intracellular free Mg2+ levels in mammalian cells. The molecular functions of free Mg2+ in eukaryotic cells have not been established. We found that patients with genetic deficiencies in MAGT1 have high levels of Epstein-Barr virus (EBV) and a predisposition to lymphoma. In studying lymphocytes from these patients, we found that a deficiency of MAGT1 caused decreased basal intracellular free Mg2+ leading to defective expression of the natural killer activating receptor NKG2D in NK and CD8+ T cells. Without NKG2D, cytolytic responses against EBV are diminished, thereby revealing the first specific molecular function of intracellular basal free Mg2+ in eukaryotic cells. Moreover, intracellular free Mg2+, NKG2D expression and function can be rescued in vitro by incubating patient cells and elevated levels of Mg2+. Moreover, NKG2D expression and cytolytic function can be improved and EBV-infected cells reduced in vivo, in MAGT1-deficient patients by magnesium administration. Thus, our data indicate an important molecular function for free basal Mg2+ in immunity and demonstrate a requirement for NKG2D cytolytic function in an essential EBV antiviral response in humans.